/**************************************************************
  > File Name: ftok.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年02月23日 星期三 01时41分08秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <unistd.h>

#define PATHNAME "/tmp/out"

int main(int argc, char **argv)
{
	struct stat statBuf;
	key_t key;
	int ret;
	int testKey;
	int proj_id = 1;

	key = ftok(PATHNAME, proj_id);
	

	ret = stat(PATHNAME, &statBuf);
	if (ret < 0)
	{
		perror("stat()");
		exit(1);
	}


	testKey = (proj_id & 0xff) << 24 | (statBuf.st_dev & 0xff) << 16 | (statBuf.st_ino & 0xffff);

	if (key == testKey)
	{
		printf("right!\n");
	}

	printf("%x\n", key);
	printf("%x\n", testKey);
    exit(0);
}
